#pragma once
#include "IOUringEventLoopThread.h"
#include "Noncopyable.h"
#include <memory>
#include <vector>
class IOUringTcpServer : Noncopyable {
    using SubLoopThreadPtr = std::shared_ptr<IOUringEventLoopThread>;
    using NewConnectionCallback =
        std::function<void(IOUringEventLoop *loop, struct io_uring_cqe *cqe)>;
    using WriteCompleteCallback =
        std::function<void(IOUringEventLoop *loop, struct io_uring_cqe *cqe)>;
    using ReadCompleteCallback =
        std::function<void(IOUringEventLoop *loop, struct io_uring_cqe *cqe)>;

  public:
    explicit IOUringTcpServer(uint32_t numSubLoop, int port)
        : numSubLoop_(numSubLoop), port_(port), listenFd_(0), servAddr_() {}
    ~IOUringTcpServer() = default;

    void start();
    void setNewConnectionCallback(NewConnectionCallback cb) {
        newConnectionCallback_ = cb;
    }
    void setWriteCompleteCallback(WriteCompleteCallback cb) {
        writeCompleteCallback_ = cb;
    }
    void setReadCompleteCallback(ReadCompleteCallback cb) {
        readCompleteCallback_ = cb;
    }

  private:
    void listen();

  private:
    std::vector<SubLoopThreadPtr> loops_;
    uint32_t numSubLoop_;
    int port_;
    int listenFd_;
    struct sockaddr_in servAddr_;

    NewConnectionCallback newConnectionCallback_;
    WriteCompleteCallback writeCompleteCallback_;
    ReadCompleteCallback readCompleteCallback_;
}; // class IOUringTcpServer
